﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ProductType : System.Web.UI.Page
{    
    DataTable dtb = new DataTable();
    string sql;

    protected void Page_Load(object sender, EventArgs e)
    {
        string request = Request.QueryString["Tenhang"];
        sql = string.Format(@"SELECT TenXe, NgoaiThat,NamSX, Image,MaXe 
                                       FROM ThongTinCoBan as a,
                                            hangxe as b 
                                       Where b.TenHang ='{0}' and a.MaHangXe=b.MaHangXe", request);
        if (!IsPostBack)
        {
            this.Display();
        }
    }
    protected void Display()
    {

        dtb = DataBase.GetDataTable(sql);
        DataList1.DataSource = dtb;
        DataList1.DataBind();
        PhanTrang();
    }
    protected void ImageButton_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton ibtn = (ImageButton)sender;
        if (IsPostBack)
        {
            Response.Redirect("~/ProductDetail.aspx?Product=" + ibtn.CommandArgument);

        }
        //{
        //    if (Request.QueryString["Tenhang"] != null && Request.QueryString["Product"] == null)
        //        Response.Redirect("~/ProductDetail.aspx?Product=" + ibtn.CommandArgument, true);
        //}
    }
    void PhanTrang()
    {

        CollectionPager1.DataSource = dtb.DefaultView;
        CollectionPager1.PageSize = 12;
        CollectionPager1.BindToControl = DataList1;
        DataList1.DataSource = CollectionPager1.DataSourcePaged;

    }
    protected void btnCartAdd_Click(object sender, ImageClickEventArgs e)
    {
        ShoppingCart cart = (ShoppingCart)Session["ShoppingCart"];

        ImageButton btn = (ImageButton)sender;
        string maxe = btn.CommandArgument;
        cart.Add(maxe, 1);

        MasterPage master = (MasterPage)this.Master;
        master.RefreshShoppingCartInfo();
    }
}
